<template>
   <div class="photoinfo-container">
       <h3>{{photoinfo.title}}</h3>
       <p class="subtitle">
           <span>发表时间：{{photoinfo.add_time | dataFormat}}</span>
           <span>点击：{{photoinfo.click}}次</span>
       </p>
       <hr>
       <!-- 缩略图区域 -->
  
       <div class="thum">
           <vue-preview :slides="list" @close="handleClose"></vue-preview>
           <!-- <img v-for="(item,index) in list" :key="item.src" :src="item.src" class="preview-img" height="100" @click="$preview.open(index, list)"> -->
       </div>

       <!-- 图片内容区 -->
       <div class="content" v-html="photoinfo.content"></div>

       <!-- 评论组件 -->
       <cmt :id="id"></cmt>
   </div>    
</template>


<script>
import comment from "../subcomponents/comment.vue";

export default {
    data() {
        return {
            id: this.$route.params.id,
            photoinfo: {},
            list: []  // 缩略图数组
        }
    },
    created() {
        this.getphotoinfo();
        this.getpreview();
    },
    methods: {
        getphotoinfo() {
            this.$http.get("api/getimageInfo/"+this.id).then(result=> {
                if(result.body.status === 0) {
                   this.photoinfo = result.body.message[0];
                }
            })
        },
        getpreview() {
            this.$http.get('api/getthumimages/'+this.id).then(result=> {
                if(result.body.status === 0) {
                    result.body.message.forEach(element => {
                        // 必要  必须配置  不然缩略图插件不能正常使用
                        element.w = 300;
                        element.h = 200;
                        element.msrc = element.src;
                    });;
                    this.list = result.body.message; 
                    console.log(this);
                }
            })
        },
        handleClose () {
           console.log('close event')
        }
    },
    components: {
        "cmt" : comment
    }
}
</script>


<style lang="scss" scoped>
.photoinfo-container {
    padding: 3px;
    margin: 0;
    h3 {
        color: #26a2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }
    .content {
        font-size: 13px;
        line-height: 30px;
    }
    .thum {
        padding: 0;
        margin: 0;
        img{
            width: 300px;
            height: 200px;
            text-align: center;
            margin: 10px;
            box-shadow: 0 0 8px #999;
        }
        
    }
}
</style>
